


--use PolePosition

-- // checksum failed custom error
--exec sp_addmessage @msgnum = 505050, @severity = 16, @msgtext = N'%s(%s) checksum compare failed', @replace = 'REPLACE', @lang = 'us_english'
GO

-- // not found custom error
--exec sp_addmessage @msgnum = 505060, @severity = 16, @msgtext = N'%s(%s) does not exist', @replace = 'REPLACE', @lang = 'us_english'
GO

-- // unit test custom error
--exec sp_addmessage @msgnum = 505070, @severity = 16, @msgtext = N'%s Test Failed. Expected< %s > Actual< %s > %s', @replace = 'REPLACE', @lang = 'us_english'
GO



--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'v_tb_Utility_Asset_XMissionStructures_Poles') and OBJECTPROPERTY(id, N'IsProcedure') = 0)
drop view v_tb_Utility_Asset_XMissionStructures_Poles
GO

create view v_tb_Utility_Asset_XMissionStructures_Poles as
	/* 	Initial Generated Date:  Thursday, March 05, 2009 
		Purpose: Selected record(s) from the table; this view is the source for all procedures' select statements
	*/
	
select
	 [Utility_Asset_XMissionStructures_PoleId] as [Utility_Asset_XMissionStructures_PoleId]
	,[Utility_Asset_XMissionStructureFK] as [Utility_Asset_XMissionStructureFK]
	,[XMissionStructures_PoleTopTypeFk] as [XMissionStructures_PoleTopTypeFk]
	,[XMissionStructures_PoleSpeciesFk] as [XMissionStructures_PoleSpeciesFk]
	,[XMissionStructures_PoleTreatmentFk] as [XMissionStructures_PoleTreatmentFk]
	,[Year] as [Year]
	,[XMissionStructures_PoleClassFk] as [XMissionStructures_PoleClassFk]
	,[Latitude] as [Latitude]
	,[Longitude] as [Longitude]
	,[Altitude] as [Altitude]
	,[SatelliteCount] as [SatelliteCount]
	,[SatelliteTime] as [SatelliteTime]
	,[SolutionAvailable] as [SolutionAvailable]
	,[AID] as [AID]
	,[LVisit] as [LVisit]
	,[Number] as [Number]
	,[Length] as [Length]
	,[LVisitor] as [LVisitor]
	,[SectionFk] as [SectionFk]
	,[MapFk] as [MapFk]
	-- customization may be required for FriendlyName
	,Left(CONVERT(varchar(255), [Utility_Asset_XMissionStructures_PoleId]), 255) as [FriendlyName]
from
	tb_Utility_Asset_XMissionStructures_Poles
GO





--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_UtilityAssetXMissionStructuresPole_Test') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_UtilityAssetXMissionStructuresPole_Test
GO


create proc up_UtilityAssetXMissionStructuresPole_Test
	@Utility_Asset_XMissionStructures_PoleId int
as
	/* 	Initial Generated Date:  Thursday, March 05, 2009 
		Purpose: Test if a record exists, using the primary key
	*/

SET NOCOUNT ON	
	
if exists(
	select [Utility_Asset_XMissionStructures_PoleId] 
	from [tb_Utility_Asset_XMissionStructures_Poles] source
	where [source].[Utility_Asset_XMissionStructures_PoleId] = @Utility_Asset_XMissionStructures_PoleId)
begin
	return(1)
end
else
begin
	return(0)
end
GO






--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_UtilityAssetXMissionStructuresPole_Select') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_UtilityAssetXMissionStructuresPole_Select
GO

create proc up_UtilityAssetXMissionStructuresPole_Select
	 @Utility_Asset_XMissionStructures_PoleId int = null 
	,@Utility_Asset_XMissionStructureFK int = null 
	,@XMissionStructures_PoleTopTypeFk int = null 
	,@XMissionStructures_PoleSpeciesFk int = null 
	,@XMissionStructures_PoleTreatmentFk int = null 
	,@Year int = null 
	,@XMissionStructures_PoleClassFk int = null 
	,@Latitude float = null 
	,@Longitude float = null 
	,@Altitude float = null 
	,@SatelliteCount int = null 
	,@SatelliteTime datetime = null 
	,@SolutionAvailable bit = null 
	,@AID nvarchar(100) = null 
	,@LVisit int = null 
	,@Number nvarchar(10) = null 
	,@Length float = null 
	,@LVisitor nvarchar(100) = null 
	,@SectionFk int = null 
	,@MapFk int = null 
as
	/* 	Initial Generated Date:  Thursday, March 05, 2009 
		Purpose: Selected record(s) based on the passed arguments; no arguments returns all
	*/

SET NOCOUNT ON	

declare @table table
	(
	 Utility_Asset_XMissionStructures_PoleId int
	,Utility_Asset_XMissionStructureFK int
	,XMissionStructures_PoleTopTypeFk int
	,XMissionStructures_PoleSpeciesFk int
	,XMissionStructures_PoleTreatmentFk int
	,Year int
	,XMissionStructures_PoleClassFk int
	,Latitude float
	,Longitude float
	,Altitude float
	,SatelliteCount int
	,SatelliteTime datetime
	,SolutionAvailable bit
	,AID nvarchar(100)
	,LVisit int
	,Number nvarchar(10)
	,Length float
	,LVisitor nvarchar(100)
	,SectionFk int
	,MapFk int
	,[FriendlyName] varchar(255)
	)
	
insert @table
	(
	 [Utility_Asset_XMissionStructures_PoleId]
	,[Utility_Asset_XMissionStructureFK]
	,[XMissionStructures_PoleTopTypeFk]
	,[XMissionStructures_PoleSpeciesFk]
	,[XMissionStructures_PoleTreatmentFk]
	,[Year]
	,[XMissionStructures_PoleClassFk]
	,[Latitude]
	,[Longitude]
	,[Altitude]
	,[SatelliteCount]
	,[SatelliteTime]
	,[SolutionAvailable]
	,[AID]
	,[LVisit]
	,[Number]
	,[Length]
	,[LVisitor]
	,[SectionFk]
	,[MapFk]
	,[FriendlyName]
	)
select 
	 [Utility_Asset_XMissionStructures_PoleId]
	,[Utility_Asset_XMissionStructureFK]
	,[XMissionStructures_PoleTopTypeFk]
	,[XMissionStructures_PoleSpeciesFk]
	,[XMissionStructures_PoleTreatmentFk]
	,[Year]
	,[XMissionStructures_PoleClassFk]
	,[Latitude]
	,[Longitude]
	,[Altitude]
	,[SatelliteCount]
	,[SatelliteTime]
	,[SolutionAvailable]
	,[AID]
	,[LVisit]
	,[Number]
	,[Length]
	,[LVisitor]
	,[SectionFk]
	,[MapFk]
	,[FriendlyName]
from v_tb_Utility_Asset_XMissionStructures_Poles
where
		IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Utility_Asset_XMissionStructures_PoleId], -1) = Coalesce(@Utility_Asset_XMissionStructures_PoleId, [v_tb_Utility_Asset_XMissionStructures_Poles].[Utility_Asset_XMissionStructures_PoleId], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Utility_Asset_XMissionStructureFK], -1) = Coalesce(@Utility_Asset_XMissionStructureFK, [v_tb_Utility_Asset_XMissionStructures_Poles].[Utility_Asset_XMissionStructureFK], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleTopTypeFk], -1) = Coalesce(@XMissionStructures_PoleTopTypeFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleTopTypeFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleSpeciesFk], -1) = Coalesce(@XMissionStructures_PoleSpeciesFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleSpeciesFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleTreatmentFk], -1) = Coalesce(@XMissionStructures_PoleTreatmentFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleTreatmentFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Year], -1) = Coalesce(@Year, [v_tb_Utility_Asset_XMissionStructures_Poles].[Year], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleClassFk], -1) = Coalesce(@XMissionStructures_PoleClassFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleClassFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Latitude], -1) = Coalesce(@Latitude, [v_tb_Utility_Asset_XMissionStructures_Poles].[Latitude], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Longitude], -1) = Coalesce(@Longitude, [v_tb_Utility_Asset_XMissionStructures_Poles].[Longitude], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Altitude], -1) = Coalesce(@Altitude, [v_tb_Utility_Asset_XMissionStructures_Poles].[Altitude], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[SatelliteCount], -1) = Coalesce(@SatelliteCount, [v_tb_Utility_Asset_XMissionStructures_Poles].[SatelliteCount], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[SatelliteTime], '1/1/1900 12:00AM') = Coalesce(@SatelliteTime, [v_tb_Utility_Asset_XMissionStructures_Poles].[SatelliteTime], '1/1/1900 12:00AM')
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[SolutionAvailable], 0) = Coalesce(@SolutionAvailable, [v_tb_Utility_Asset_XMissionStructures_Poles].[SolutionAvailable], 0)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[AID], '') = Coalesce(@AID, [v_tb_Utility_Asset_XMissionStructures_Poles].[AID], '')
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[LVisit], -1) = Coalesce(@LVisit, [v_tb_Utility_Asset_XMissionStructures_Poles].[LVisit], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Number], '') = Coalesce(@Number, [v_tb_Utility_Asset_XMissionStructures_Poles].[Number], '')
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Length], -1) = Coalesce(@Length, [v_tb_Utility_Asset_XMissionStructures_Poles].[Length], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[LVisitor], '') = Coalesce(@LVisitor, [v_tb_Utility_Asset_XMissionStructures_Poles].[LVisitor], '')
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[SectionFk], -1) = Coalesce(@SectionFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[SectionFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[MapFk], -1) = Coalesce(@MapFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[MapFk], -1)

-- primary select
select * from @table





	-- UtilityAssetXMissionStructuresImageCollection select

select
	v_tb_Utility_Asset_XMissionStructures_Images.* 
from 
	v_tb_Utility_Asset_XMissionStructures_Images 
	JOIN @table x ON v_tb_Utility_Asset_XMissionStructures_Images.Utility_Asset_XMissionStructures_PoleFK = x.Utility_Asset_XMissionStructures_PoleId
	

	
GO 





--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_UtilityAssetXMissionStructuresPole_Select_Top1') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_UtilityAssetXMissionStructuresPole_Select_Top1
GO

create proc up_UtilityAssetXMissionStructuresPole_Select_Top1
	 @Utility_Asset_XMissionStructures_PoleId int = null 
	,@Utility_Asset_XMissionStructureFK int = null 
	,@XMissionStructures_PoleTopTypeFk int = null 
	,@XMissionStructures_PoleSpeciesFk int = null 
	,@XMissionStructures_PoleTreatmentFk int = null 
	,@Year int = null 
	,@XMissionStructures_PoleClassFk int = null 
	,@Latitude float = null 
	,@Longitude float = null 
	,@Altitude float = null 
	,@SatelliteCount int = null 
	,@SatelliteTime datetime = null 
	,@SolutionAvailable bit = null 
	,@AID nvarchar(100) = null 
	,@LVisit int = null 
	,@Number nvarchar(10) = null 
	,@Length float = null 
	,@LVisitor nvarchar(100) = null 
	,@SectionFk int = null 
	,@MapFk int = null 
as
	/* 	Initial Generated Date:  Thursday, March 05, 2009 
		Purpose: Selected record(s) based on the passed arguments; no arguments returns all
	*/

SET NOCOUNT ON	

declare @table table
	(
	  Utility_Asset_XMissionStructures_PoleId int
	, Utility_Asset_XMissionStructureFK int
	, XMissionStructures_PoleTopTypeFk int
	, XMissionStructures_PoleSpeciesFk int
	, XMissionStructures_PoleTreatmentFk int
	, Year int
	, XMissionStructures_PoleClassFk int
	, Latitude float
	, Longitude float
	, Altitude float
	, SatelliteCount int
	, SatelliteTime datetime
	, SolutionAvailable bit
	, AID nvarchar(100)
	, LVisit int
	, Number nvarchar(10)
	, Length float
	, LVisitor nvarchar(100)
	, SectionFk int
	, MapFk int
	,[FriendlyName] varchar(255)
	)

insert @table
	(
	 [Utility_Asset_XMissionStructures_PoleId]
	,[Utility_Asset_XMissionStructureFK]
	,[XMissionStructures_PoleTopTypeFk]
	,[XMissionStructures_PoleSpeciesFk]
	,[XMissionStructures_PoleTreatmentFk]
	,[Year]
	,[XMissionStructures_PoleClassFk]
	,[Latitude]
	,[Longitude]
	,[Altitude]
	,[SatelliteCount]
	,[SatelliteTime]
	,[SolutionAvailable]
	,[AID]
	,[LVisit]
	,[Number]
	,[Length]
	,[LVisitor]
	,[SectionFk]
	,[MapFk]
	,[FriendlyName]
	)
select TOP 1
	 [Utility_Asset_XMissionStructures_PoleId]
	,[Utility_Asset_XMissionStructureFK]
	,[XMissionStructures_PoleTopTypeFk]
	,[XMissionStructures_PoleSpeciesFk]
	,[XMissionStructures_PoleTreatmentFk]
	,[Year]
	,[XMissionStructures_PoleClassFk]
	,[Latitude]
	,[Longitude]
	,[Altitude]
	,[SatelliteCount]
	,[SatelliteTime]
	,[SolutionAvailable]
	,[AID]
	,[LVisit]
	,[Number]
	,[Length]
	,[LVisitor]
	,[SectionFk]
	,[MapFk]
	,[FriendlyName]
from v_tb_Utility_Asset_XMissionStructures_Poles
where
		IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Utility_Asset_XMissionStructures_PoleId], -1) = Coalesce(@Utility_Asset_XMissionStructures_PoleId, [v_tb_Utility_Asset_XMissionStructures_Poles].[Utility_Asset_XMissionStructures_PoleId], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Utility_Asset_XMissionStructureFK], -1) = Coalesce(@Utility_Asset_XMissionStructureFK, [v_tb_Utility_Asset_XMissionStructures_Poles].[Utility_Asset_XMissionStructureFK], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleTopTypeFk], -1) = Coalesce(@XMissionStructures_PoleTopTypeFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleTopTypeFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleSpeciesFk], -1) = Coalesce(@XMissionStructures_PoleSpeciesFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleSpeciesFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleTreatmentFk], -1) = Coalesce(@XMissionStructures_PoleTreatmentFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleTreatmentFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Year], -1) = Coalesce(@Year, [v_tb_Utility_Asset_XMissionStructures_Poles].[Year], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleClassFk], -1) = Coalesce(@XMissionStructures_PoleClassFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[XMissionStructures_PoleClassFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Latitude], -1) = Coalesce(@Latitude, [v_tb_Utility_Asset_XMissionStructures_Poles].[Latitude], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Longitude], -1) = Coalesce(@Longitude, [v_tb_Utility_Asset_XMissionStructures_Poles].[Longitude], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Altitude], -1) = Coalesce(@Altitude, [v_tb_Utility_Asset_XMissionStructures_Poles].[Altitude], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[SatelliteCount], -1) = Coalesce(@SatelliteCount, [v_tb_Utility_Asset_XMissionStructures_Poles].[SatelliteCount], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[SatelliteTime], '1/1/1900 12:00AM') = Coalesce(@SatelliteTime, [v_tb_Utility_Asset_XMissionStructures_Poles].[SatelliteTime], '1/1/1900 12:00AM')
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[SolutionAvailable], 0) = Coalesce(@SolutionAvailable, [v_tb_Utility_Asset_XMissionStructures_Poles].[SolutionAvailable], 0)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[AID], '') = Coalesce(@AID, [v_tb_Utility_Asset_XMissionStructures_Poles].[AID], '')
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[LVisit], -1) = Coalesce(@LVisit, [v_tb_Utility_Asset_XMissionStructures_Poles].[LVisit], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Number], '') = Coalesce(@Number, [v_tb_Utility_Asset_XMissionStructures_Poles].[Number], '')
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[Length], -1) = Coalesce(@Length, [v_tb_Utility_Asset_XMissionStructures_Poles].[Length], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[LVisitor], '') = Coalesce(@LVisitor, [v_tb_Utility_Asset_XMissionStructures_Poles].[LVisitor], '')
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[SectionFk], -1) = Coalesce(@SectionFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[SectionFk], -1)
	AND	IsNull([v_tb_Utility_Asset_XMissionStructures_Poles].[MapFk], -1) = Coalesce(@MapFk, [v_tb_Utility_Asset_XMissionStructures_Poles].[MapFk], -1)

-- primary select
select * from @table


	-- UtilityAssetXMissionStructuresImageCollection select

select
	v_tb_Utility_Asset_XMissionStructures_Images.* 
from 
	v_tb_Utility_Asset_XMissionStructures_Images 
	JOIN @table x ON v_tb_Utility_Asset_XMissionStructures_Images.Utility_Asset_XMissionStructures_PoleFK = x.Utility_Asset_XMissionStructures_PoleId
	
	
	
GO 





--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_UtilityAssetXMissionStructuresPole_Insert') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_UtilityAssetXMissionStructuresPole_Insert
GO

create proc up_UtilityAssetXMissionStructuresPole_Insert
	 @Utility_Asset_XMissionStructures_PoleId int =null OUTPUT  
	,@Utility_Asset_XMissionStructureFK int  
	,@XMissionStructures_PoleTopTypeFk int = null  
	,@XMissionStructures_PoleSpeciesFk int = null  
	,@XMissionStructures_PoleTreatmentFk int = null  
	,@Year int = null  
	,@XMissionStructures_PoleClassFk int = null  
	,@Latitude float = null  
	,@Longitude float = null  
	,@Altitude float = null  
	,@SatelliteCount int = null  
	,@SatelliteTime datetime = null  
	,@SolutionAvailable bit  
	,@AID nvarchar(100) = null  
	,@LVisit int = null  
	,@Number nvarchar(10) = null  
	,@Length float = null  
	,@LVisitor nvarchar(100) = null  
	,@SectionFk int = null  
	,@MapFk int = null  
as
	/* 	Initial Generated Date:  Thursday, March 05, 2009 
		Purpose: Inserts a new record; missing arguments are set as their default (typically null)
	*/

SET NOCOUNT ON	
--int

insert tb_Utility_Asset_XMissionStructures_Poles 
	(
	
	 [Utility_Asset_XMissionStructureFK] 
	,[XMissionStructures_PoleTopTypeFk] 
	,[XMissionStructures_PoleSpeciesFk] 
	,[XMissionStructures_PoleTreatmentFk] 
	,[Year] 
	,[XMissionStructures_PoleClassFk] 
	,[Latitude] 
	,[Longitude] 
	,[Altitude] 
	,[SatelliteCount] 
	,[SatelliteTime] 
	,[SolutionAvailable] 
	,[AID] 
	,[LVisit] 
	,[Number] 
	,[Length] 
	,[LVisitor] 
	,[SectionFk] 
	,[MapFk] 
	)
	values
	(
	
	 @Utility_Asset_XMissionStructureFK 
	,@XMissionStructures_PoleTopTypeFk 
	,@XMissionStructures_PoleSpeciesFk 
	,@XMissionStructures_PoleTreatmentFk 
	,@Year 
	,@XMissionStructures_PoleClassFk 
	,@Latitude 
	,@Longitude 
	,@Altitude 
	,@SatelliteCount 
	,@SatelliteTime 
	,@SolutionAvailable 
	,@AID 
	,@LVisit 
	,@Number 
	,@Length 
	,@LVisitor 
	,@SectionFk 
	,@MapFk 
	)
set @Utility_Asset_XMissionStructures_PoleId = scope_identity()
select * from v_tb_Utility_Asset_XMissionStructures_Poles where Utility_Asset_XMissionStructures_PoleId = @Utility_Asset_XMissionStructures_PoleId

GO




--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_UtilityAssetXMissionStructuresPole_Update') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_UtilityAssetXMissionStructuresPole_Update
GO


create proc up_UtilityAssetXMissionStructuresPole_Update
	 @Utility_Asset_XMissionStructures_PoleId int  
	,@Utility_Asset_XMissionStructureFK int = null  
	,@XMissionStructures_PoleTopTypeFk int = null  
	,@XMissionStructures_PoleSpeciesFk int = null  
	,@XMissionStructures_PoleTreatmentFk int = null  
	,@Year int = null  
	,@XMissionStructures_PoleClassFk int = null  
	,@Latitude float = null  
	,@Longitude float = null  
	,@Altitude float = null  
	,@SatelliteCount int = null  
	,@SatelliteTime datetime = null  
	,@SolutionAvailable bit = null  
	,@AID nvarchar(100) = null  
	,@LVisit int = null  
	,@Number nvarchar(10) = null  
	,@Length float = null  
	,@LVisitor nvarchar(100) = null  
	,@SectionFk int = null  
	,@MapFk int = null  
	,@OriginalUtility_Asset_XMissionStructures_PoleId int  = null --Original PrimaryKey
	
as
	/* 	Initial Generated Date:  Thursday, March 05, 2009 
		Purpose: Updates an existing record, verifying exist; missing arguments persist original record value
		NOTE: this version of the update allows up to write nulls to the table.
	*/

SET NOCOUNT ON	

if @OriginalUtility_Asset_XMissionStructures_PoleId is null
	set @OriginalUtility_Asset_XMissionStructures_PoleId = @Utility_Asset_XMissionStructures_PoleId

-- test
declare @Result bit
execute @Result = up_UtilityAssetXMissionStructuresPole_Test @OriginalUtility_Asset_XMissionStructures_PoleId
if (not @Result = 1)
begin
	Declare @x varchar(100)
	Set @x = Convert(Varchar(100), @Utility_Asset_XMissionStructures_PoleId)
	raiserror(505060, 16, 1, 'UtilityAssetXMissionStructuresPole', @x)
	return
end

-- proceed
update tb_Utility_Asset_XMissionStructures_Poles 
set

	 [Utility_Asset_XMissionStructureFK] = IsNull(@Utility_Asset_XMissionStructureFK, [source].[Utility_Asset_XMissionStructureFK])
	,[XMissionStructures_PoleTopTypeFk] =  @XMissionStructures_PoleTopTypeFk
	,[XMissionStructures_PoleSpeciesFk] =  @XMissionStructures_PoleSpeciesFk
	,[XMissionStructures_PoleTreatmentFk] =  @XMissionStructures_PoleTreatmentFk
	,[Year] =  @Year
	,[XMissionStructures_PoleClassFk] =  @XMissionStructures_PoleClassFk
	,[Latitude] =  @Latitude
	,[Longitude] =  @Longitude
	,[Altitude] =  @Altitude
	,[SatelliteCount] =  @SatelliteCount
	,[SatelliteTime] =  @SatelliteTime
	,[SolutionAvailable] = IsNull(@SolutionAvailable, [source].[SolutionAvailable])
	,[AID] =  @AID
	,[LVisit] =  @LVisit
	,[Number] =  @Number
	,[Length] =  @Length
	,[LVisitor] =  @LVisitor
	,[SectionFk] =  @SectionFk
	,[MapFk] =  @MapFk
	
from tb_Utility_Asset_XMissionStructures_Poles source
where
	[source].[Utility_Asset_XMissionStructures_PoleId] = @OriginalUtility_Asset_XMissionStructures_PoleId


select * from v_tb_Utility_Asset_XMissionStructures_Poles where Utility_Asset_XMissionStructures_PoleId = @Utility_Asset_XMissionStructures_PoleId
GO





--use PolePosition

if exists (select * from dbo.sysobjects where id = object_id(N'up_UtilityAssetXMissionStructuresPole_Delete') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure up_UtilityAssetXMissionStructuresPole_Delete
GO


create proc up_UtilityAssetXMissionStructuresPole_Delete
	@Utility_Asset_XMissionStructures_PoleId int
as
	/* 	Initial Generated Date:  Thursday, March 05, 2009 
		Purpose: Deletes an existing record, verifying exist
	*/

SET NOCOUNT ON	

-- test
declare @Result bit
execute @Result = up_UtilityAssetXMissionStructuresPole_Test @Utility_Asset_XMissionStructures_PoleId
if (not @Result = 1)
begin
	Declare @x varchar(100)
	Set @x = Convert(Varchar(100), @Utility_Asset_XMissionStructures_PoleId)
	raiserror(505060, 16, 1, 'UtilityAssetXMissionStructuresPole', @x)
	return
end

-- proceed
delete from tb_Utility_Asset_XMissionStructures_Poles 
where [Utility_Asset_XMissionStructures_PoleId] = @Utility_Asset_XMissionStructures_PoleId

GO


